package com.lc.ibps.platform.rest.token;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lc.ibps.cloud.entity.APIResult;
import com.lc.ibps.components.token.model.Token;
import com.lc.ibps.components.token.model.TokenResult;
import com.lc.ibps.web.controller.BaseApiController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 获取临时token的服务。
 *
 * <pre>
 *  
 * 构建组：ibps-platform-webapi
 * 作者：hugh zhuang
 * 邮箱：3378340995@qq.com
 * 日期：2016年3月16日-上午10:35:07
 * 版权：广州流辰信息技术有限公司版权所有
 * </pre>
 */
@RequestMapping(value="/api/tokenService")
@Api(value="/tokenService",tags = "授权管理-授权服务")
@RestController
public class TokenController extends BaseApiController{

	@RequestMapping(value="/getAnonymousToken",method=RequestMethod.GET)
	@ApiOperation(value = "获取匿名token", notes = "获取匿名token")
	public APIResult<TokenResult> getAnonymousTokenJson(
			@ApiParam(name = "validCode", value = "validCode", required = true) 
			@RequestParam(name = "validCode", required = true) String validCode) {
		APIResult<TokenResult> result = new APIResult<>();
		try {
			result.setData(TokenUtil.getTokenResult(validCode, Token.TOKEN_ANONYMOUS));
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取匿名token失败！", e);
		}
		return result;
	}

	@RequestMapping(value="/getFormalToken",method=RequestMethod.GET)
	@ApiOperation(value = "获取显名token", notes = "获取显名token")
	public APIResult<TokenResult> getFormalToken(
			@ApiParam(name = "validCode", value = "validCode", required = true) 
			@RequestParam(name = "validCode", required = true) String validCode) {
		APIResult<TokenResult> result = new APIResult<>();
		try {
			result.setData(TokenUtil.getTokenResult(validCode, Token.TOKEN_FORMAL));
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取显名token失败！", e);
		}
		return result;
	}

}
